package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAPeopleList;
import com.ruoyi.system.service.ISysAPeopleListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 便民电话列表Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/people")
public class SysAPeopleListController extends BaseController
{
    private String prefix = "system/people";

    @Autowired
    private ISysAPeopleListService sysAPeopleListService;

    @RequiresPermissions("system:people:view")
    @GetMapping()
    public String people()
    {
        return prefix + "/people";
    }

    /**
     * 查询便民电话列表列表
     */
    @RequiresPermissions("system:people:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAPeopleList sysAPeopleList)
    {
        startPage();
        List<SysAPeopleList> list = sysAPeopleListService.selectSysAPeopleListList(sysAPeopleList);
        return getDataTable(list);
    }

    /**
     * 导出便民电话列表列表
     */
    @RequiresPermissions("system:people:export")
    @Log(title = "便民电话列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAPeopleList sysAPeopleList)
    {
        List<SysAPeopleList> list = sysAPeopleListService.selectSysAPeopleListList(sysAPeopleList);
        ExcelUtil<SysAPeopleList> util = new ExcelUtil<SysAPeopleList>(SysAPeopleList.class);
        return util.exportExcel(list, "便民电话列表数据");
    }

    /**
     * 新增便民电话列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存便民电话列表
     */
    @RequiresPermissions("system:people:add")
    @Log(title = "便民电话列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAPeopleList sysAPeopleList)
    {
        return toAjax(sysAPeopleListService.insertSysAPeopleList(sysAPeopleList));
    }

    /**
     * 修改便民电话列表
     */
    @GetMapping("/edit/{peopleId}")
    public String edit(@PathVariable("peopleId") Long peopleId, ModelMap mmap)
    {
        SysAPeopleList sysAPeopleList = sysAPeopleListService.selectSysAPeopleListByPeopleId(peopleId);
        mmap.put("sysAPeopleList", sysAPeopleList);
        return prefix + "/edit";
    }

    /**
     * 修改保存便民电话列表
     */
    @RequiresPermissions("system:people:edit")
    @Log(title = "便民电话列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAPeopleList sysAPeopleList)
    {
        return toAjax(sysAPeopleListService.updateSysAPeopleList(sysAPeopleList));
    }

    /**
     * 删除便民电话列表
     */
    @RequiresPermissions("system:people:remove")
    @Log(title = "便民电话列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAPeopleListService.deleteSysAPeopleListByPeopleIds(ids));
    }
}
